import pandas

data = pandas.read_csv(r"C:\Users\86189\Downloads\week-8-session-1-main\week-8-session-1-main\activity-2-pandas\lifestyle_data.csv")

# Find the total number of students
total_students = data.shape[0]
print("total number of students", total_students)

# Find the mean average GPA of the students
average_GPA = data['GPA'].mean()
print("the mean average GPA", average_GPA)

# Find the standard deviation of how much sleep students get per day
sleep_hours_standard_deviation = data['Sleep_Hours_Per_Day'].std()
print("the standard deviation of how much sleep students get per day", sleep_hours_standard_deviation)

# Find the maximum amount of study hours per day
max_study_hour = data['Study_Hours_Per_Day'].max()
print("the maximum amount of study hours per day", max_study_hour)

# Sort the students by social hours per day ascending (lowest -> highest)
data_sorted = data.sort_values(by='Social_Hours_Per_Day', ascending=True)
print("Sorted data by social hours (first 5 rows):")
print(data_sorted.head())

# Add a column 'Total_hours' which adds together all the Hours_Per_Day columns into one
hours_columns = ['Study_Hours_Per_Day', 'Extracurricular_Hours_Per_Day', 
                'Sleep_Hours_Per_Day', 'Social_Hours_Per_Day', 
                'Physical_Activity_Hours_Per_Day']
data['Total_hours'] = data[hours_columns].sum(axis=1)
print("Added Total_hours column:")
print(data[['Study_Hours_Per_Day', 'Extracurricular_Hours_Per_Day', 'Total_hours']].head())

# Filter all students with a 'high' stress level, and all the students with a 'low' stress level.
high_stress = data[data['Stress_Level'] == 'High']
low_stress = data[data['Stress_Level'] == 'Low']
print(f"Number of high stress students: {len(high_stress)}")
print(f"Number of low stress students: {len(low_stress)}")

# Can you work out whether having a higher stress level leads to a higher GPA?
# 比较高低压力组的平均GPA
high_stress_gpa = high_stress['GPA'].mean()
low_stress_gpa = low_stress['GPA'].mean()

print(f"Average GPA for high stress students: {high_stress_gpa}")
print(f"Average GPA for low stress students: {low_stress_gpa}")

if high_stress_gpa > low_stress_gpa:
    print("高压力会有更高gpa")
else:
    print("高压力不会有更高gpa")

